package com.rpay.dao.wallet;

import com.rpay.model.wallet.WalletDO;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class WalletDao {
    @Autowired
    @Qualifier("readSqlSession")
    private SqlSessionTemplate readSqlSession;

    @Autowired
    @Qualifier("writeSqlSession")
    private SqlSessionTemplate writeSqlSession;

    public List<WalletDO> list() {
        return readSqlSession.selectList("rpay.wallet.list", null);
    }

    public int post(WalletDO walletDO) {
        return writeSqlSession.insert("rpay.wallet.post", walletDO);
    }

    public int delete(Integer id) {
        return writeSqlSession.update("rpay.wallet.delete", id);
    }

    public int patch(WalletDO walletDO) {
        return writeSqlSession.update("rpay.wallet.patch", walletDO);
    }

    public WalletDO findById(int walletId) {
        return readSqlSession.selectOne("rpay.wallet.findById", walletId);
    }
}
